<?php
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );

class PimModelRole extends JModel {
	
	function __construct() {
		parent::__construct();
	}
	
	function count($where) {
		$query = "SELECT count(id) FROM #__role_pim $where";
		$this->_db->setQuery($query);
		return $this->_db->loadResult();
	}
	
	function getData(&$total, &$dbrows , $order_by = 'ro.id', $order_dir = 'DESC', $offset = 0, $limit = 30, $where=array()) {
		if(sizeof($where) > 0)
			$where = 'WHERE ' . implode(' AND ', $where);
		else
			$where = '';
		
		if($limit !== 0)
			$limit = "LIMIT $offset, $limit";
		else
			$limit = '';
			
		$query = "SELECT ro.*, g.title as g_title FROM #__role_pim as ro ";
		$query.= " LEFT JOIN #__usergroups as g ON (ro.group_id = g.id ) ";
		$query.= " $where ORDER BY ro.id ";
		$this->_db->setQuery($query);
		$dbrows	= $this->_db->loadObjectList();

		$total = $this->count($where);
	}
	
	function getLoadObj($role_id) {
		
		$query = "SELECT ro.*, g.title as g_title FROM #__role_pim as ro ";
		$query.= " LEFT JOIN #__usergroups as g ON (ro.group_id = g.id ) ";
		$query.= " WHERE ro.id= $role_id";
		
		$this->_db->setQuery($query);
		$dbrows	= $this->_db->loadObject();
		return $dbrows;

	}
	
	function getLoadObjByGroup($g_id) {
		
		$query = "SELECT ro.*, g.title as g_title FROM #__role_pim as ro ";
		$query.= " LEFT JOIN #__usergroups as g ON (ro.group_id = g.id ) ";
		$query.= " WHERE ro.group_id= $g_id";
		
		$this->_db->setQuery($query);
		$dbrows	= $this->_db->loadObject();
		return $dbrows;

	}
	
}